-module(rpsgame).
-export([play/1]).

%% Play a game of rock-paper-scissors
play(PlayerAttack) ->
	ComputerAttack = rock, %% computer attack is hard-coded
  Result = get_result(PlayerAttack, ComputerAttack),
  {Result, {player, PlayerAttack}, {computer, ComputerAttack}}.

get_result(PlayerAttack, ComputerAttack) ->
  case PlayerAttack of
    rock -> 
      case ComputerAttack of 
        rock -> draw;
        paper -> lose;
        scissors -> win
      end;
    paper ->
      case ComputerAttack of 
        rock -> win;
        paper -> draw;
        scissors -> lose
      end;
    scissors ->
      case ComputerAttack of
        rock -> lose;
        paper -> win;
        scissors -> draw
      end
  end.
